package org.gitos.cloud.server.mq.logic;


import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import org.gitos.cloud.domain.comm.Constant;
import org.gitos.cloud.domain.mq.MqMsg;
import org.gitos.cloud.domain.tcp.Bucket;
import org.gitos.cloud.server.mq.PushManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Created by szc on 2015/12/4.
 */
public class HeartBeatHandler implements Runnable {

    private PushManager pushManager;
    private String channleId;
    private String nodeId;
    private MqMsg msg;

    public MqMsg getMsg() {
        return msg;
    }

    public void setMsg(MqMsg msg) {
        this.msg = msg;
    }

    public PushManager getPushManager() {
        return pushManager;
    }

    public void setPushManager(PushManager pushManager) {
        this.pushManager = pushManager;
    }

    public String getChannleId() {
        return channleId;
    }

    public void setChannleId(String channleId) {
        this.channleId = channleId;
    }

    public String getNodeId() {
        return nodeId;
    }

    public void setNodeId(String nodeId) {
        this.nodeId = nodeId;
    }

    @Override
    public void run() {
        MqMsg resultMsg = new MqMsg();
        resultMsg.setChannelId(channleId);
        resultMsg.setNodeId(nodeId);
        Bucket bucket = new Bucket();
        bucket.setCmd(Constant.CMD_DOWN_HEART_BEAT);
        bucket.setContent(new byte[]{0x01});
        bucket.setDeviceId(msg.getBucket().getDeviceId());
        resultMsg.setBucket(bucket);
        pushManager.sendMsg(resultMsg.getNodeId(), resultMsg);
    }
}
